var util = require('../../../utils/util.js');
Page({

  data: {
    info:{},
    statues:""
  },
  onLoad: function (options) {
    console.log(options)
    wx.cloud.callFunction({
      name:"get-pro-MessageChannel",
      data:{
        phone:options.phone
      }
    }).then(res=>{
      console.log(res.result[0])
      this.setData({
        info:res.result[0]
      })
        var timeTamp=this.data.info.time
        var localtime=this.data.localtime
        var num=localtime-timeTamp

        var days=(num/86400).toFixed(0)  //转换为多少天
        console.log(days)
        var remain=num%86400

        var hours=(remain/3600).toFixed(0)
        console.log(hours)
        this.setData({
          days:days,
          hours:hours
        })
        if(days<1){
          this.setData({
            statues:"有效期内,已使用"+this.data.hours+"小时"
          })
        }else if(days<=30){
          this.setData({
            statues:"有效期内,已使用"+this.data.days+"天"
          })
        }else{
          this.setData({
            statues:"二维码失效"
          })
        }
    })
  },
  onShow:function(){
     //获取时间戳
     this.time = new Date();
     var localtime = Date.parse(this.time)/ 1000;
     console.log(localtime)
     //时间戳转换
     var date = util.formatTime(this.time);
     this.setData({ time: date,localtime:localtime})
  },
  btn:function(){
    console.log(this.data.info)
    wx.cloud.callFunction({
      name:"update-teachpro-time",
      data:{
        time:this.data.localtime,
        phone:this.data.info.phone
      }
    }).then(res=>{
      wx.showToast({
        title: '续签成功',
        icon: 'loading',
        mask:true,
        duration: 2000,
        success:function(){
					setTimeout(function () {
						//要延时执行的代码
            wx.navigateBack({})
					}, 1000) //延迟时间
        }
      })
    })
  }
})